#include<bits/stdc++.h>
using namespace std;
int t,tt;
int a[100007];
int cnt[1007];

void solve(){
	cout << "Case " << t - tt << ":" << "\n";
	int n,q;
	cin >> n >> q;
	
	for(int i = 0;i < n;i++){
		cin >> a[i];
	}
	for(int i = 1;i <= q;i++){
		int l,r;
		cin >> l >> r;
		memset(cnt,0,sizeof(cnt));
		for(int j = l;j <= r;j++){
			cnt[a[j]]++;
		}
		int ans = 0x3f3f3f3f;
		int pre = -ans;
	
		for(int j = 1;j <= 1000;j++){
			//没出现过的数字就跳过
			if(cnt[j] == 0){
				continue;
			}
			//说明有数字重复出现
			if(cnt[j] >= 2){
				ans = 0;
				break;
			}
			ans = min(ans,j - pre);
			//pre存储上一次出现过的数字
			pre = j;
		}
		cout << ans << "\n";
	}
}
int main(){
	cin >> t;
	tt = t;
	while(tt--) solve();
}